//
// Created by edward on 23-2-9.
//

#ifndef CONCURRENCE_SPINLOCKMUTEX_H
#define CONCURRENCE_SPINLOCKMUTEX_H

#include <atomic>


namespace edward::multithread {

    class SpinLockMutex {
        std::atomic_flag flag_;
    public:
        SpinLockMutex(): flag_(ATOMIC_FLAG_INIT) {}

        void lock() {
            while (flag_.test_and_set(std::memory_order_acquire));
        }

        void unlock() {
            flag_.clear(std::memory_order_release);
        }
    };

}



#endif //CONCURRENCE_SPINLOCKMUTEX_H
